package com.crm.system.controller.worklog;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.worklog.WorkLogQO;
import com.crm.model.vo.worklog.WorkLogAddVO;
import com.crm.model.vo.worklog.WorkLogQueryVO;
import com.crm.system.service.worklog.WorkLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * @Description: 工作日志
 * @Author lixq-f
 * @Date 2021/6/25
 * @Version V1.0
 **/
@RestController
@RequestMapping("/workLog")
public class WorkLogController {


    @Autowired
    private WorkLogService workLogService;


    /**
     * @Description: 查询工作日志列表
     * @Param: [pageIndex, pageSize, sortName, sortOrder, workLogQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/25
    **/
    @PostMapping("/selectWorkLogListByPage")
    public DataResponse selectWorkLogListByPage(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,//页码
                                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,//分页大小
                                                @RequestParam(value = "sortName", required = false) String sortName,//排序列名字
                                                @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则(asc/desc)
                                                WorkLogQO workLogQO
    ){
        DhPageInfo<WorkLogQueryVO> pageInfo = workLogService.selectWorkLogListByPage(pageIndex, pageSize, sortName, sortOrder, workLogQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageInfo);
    }


    /**
     * @Description: 添加工作日志
     * @Param: [workLogVO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/25
    **/
    @PostMapping("/addWorkLog")
    public DataResponse addWorkLog(@Valid @RequestBody WorkLogAddVO workLogVO){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogService.addWorkLog(workLogVO));
    }


    /**
     * @Description: 编辑工作日志
     * @Param: [workLogVO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/25
     **/
    @PostMapping("/updateWorkLog")
    public DataResponse updateWorkLog(@Valid @RequestBody WorkLogAddVO workLogVO){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogService.updateWorkLog(workLogVO));
    }


    /**
     * @Description: 删除日志
     * @Param: [logId]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/25
    **/
    @PostMapping("/delLogById/{logId}")
    public DataResponse deleteKnItemById(@PathVariable("logId") String logId){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogService.deleteById(logId));
    }


    /**
     * @Description: 根据ID获取数据
     * @Param: [logId]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/30
    **/
    @GetMapping("/getLogById/{logId}")
    public DataResponse getLogById(@PathVariable("logId") String logId){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogService.getLogById(logId));
    }



}
